//
//  PlaySoundByType.m
//  Staff
//
//  Created by caiyao on 1/13/15.
//
//

#import "PlaySoundByType.h"
#import <AudioToolbox/AudioToolbox.h>

@implementation PlaySoundByType

- (void)excute {
    
    NSString *type = [self.command.functionParamsDic objectForKey:@"type"];
    
    if ((type!=nil) &&
        ([type isEqualToString:@"match"]))
    {
        SystemSoundID soundID;
        
        NSString *name = @"shake_match";
        
        NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
        
        AudioServicesPlaySystemSound(soundID);
    }
    else if ((type!=nil) &&
             ([type isEqualToString:@"unmatch"]))
    {
        SystemSoundID soundID;
        
        NSString *name = @"shake_nomatch";
        
        NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
        
        AudioServicesPlaySystemSound(soundID);
    }
    else if ((type!=nil) &&
             ([type isEqualToString:@"result"]))
    {
        SystemSoundID soundID;
        
        NSString *name = @"shake_match";
        
        NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
        
        AudioServicesPlaySystemSound(soundID);
    }/*
      else if ((type!=nil) &&
      ([type isEqualToString:@"unlock"]))
      {
      SystemSoundID soundID;
      
      NSString *name = @"unlock";
      
      NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"mp3"];
      AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
      
      AudioServicesPlaySystemSound(soundID);
      }*/
    else
    {
        // TODO nothing
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:COMMAND_EXCUTE_DONE_NOTIFICATION object:self];


}

@end
